var express = require('express');
var http = require('http');
var router = express.Router();
router.use(function timeLog(req, res, next) {
  console.log('Time: ', Date.now());
  next();
});
router.get('/add.js', function (req, res1) {
  console.log(req.headers["user-agent"]);
  	var data = require('querystring').stringify({"name":"gy1206"});
	var opt = {
	     host:'localhost',
	     port:'3001',
	     method:'get',
	     path:'/show.json?name=gy1206'
	     // headers:{
	     //      'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8',
	     //      'Content-Length':data.length
	     // }
	}

	var body = '';
	var getrequest = http.request(opt, function(res) {
	    console.log("Got response: " + res.statusCode);
	    // body = res;
	    res.on('data',function(d){
	        body += d;
	    }).on('end', function(){
	        console.log(res.headers)
	        console.log(getrequest.body);
	        res1.send(body);
	    });
	}).on('error', function(e) {
	    console.log("Got error: " + e.message);
	})
	getrequest.write(data);
	getrequest.end();
});
module.exports = router;